package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCAreaType;
import com.navinfo.stream.qingqi.protocol.java.LCLocationData.SpeedAddition;

public class SpeedAdditionDto {
    private String types;
    private long areaId;
    private long lineId;

    public String getTypes() {
        return types;
    }
    public void setTypes(String types) {
        this.types = types;
    }
    public long getAreaId() {
        return areaId;
    }
    public void setAreaId(long areaId) {
        this.areaId = areaId;
    }
    public long getLineId() {
        return lineId;
    }
    public void setLineId(long lineId) {
        this.lineId = lineId;
    }

    /**
     * 解析成String拼接字符串
     * @param speedAddition
     * @return
     */
    public static String parseString(SpeedAddition speedAddition){
        return EntityConvert.convert(
                speedAddition.getAreaId(),
                speedAddition.getTypes().getNumber(),
                speedAddition.getLineId());
    }
    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static SpeedAddition parsePB(String str){
        SpeedAddition.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=3){
                builder = SpeedAddition.newBuilder();
                builder.setAreaId(Long.valueOf(revert[0]));
                builder.setLineId(Long.valueOf(revert[1]));
                builder.setTypes(LCAreaType.AreaType.valueOf(revert[2]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }
}
